<?php
/**
 * Created by PhpStorm.
 * 订单
 */
namespace App\frontend\controllers\orders;

use App\common\components\BaseController;
use App\frontend\models\OrderModel;
use App\frontend\services\orders\OrderServices;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class OrderController extends BaseController
{
    protected $class_name = 'Orders';

    /**
     * 获取订单列表
     * $id     int      默认为0
     * $title  string   默认为空
     * @desc 获取订单列表的信息
     */
    public function getOrdersList(Request $request)
    {
        $data = self::getData($this->class_name,'getOrdersList');
        if ($data) {
            return $data;
        }
        $validator = Validator::make(
            $request->all(),
            OrderModel::rules(),
            OrderModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return errorJson($msg[0], []);
        }
        $list = OrderServices::getList($data);
        return successJson('获取订单数据成功!', $list);
    }

    /**
     * 获取订单详情
     * $id     int      默认为0
     * $title  string   默认为空
     * @desc 获取订单详情的信息
     */
    public function createOrders(Request $request)
    {
        $data = self::getData($this->class_name,'createOrders');
        if ($data) {
            return $data;
        }
        $validator = Validator::make(
            $request->all(),
            OrderModel::rules(),
            OrderModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return errorJson($msg[0], []);
        }
        $list = OrderServices::getList($data);
        return successJson('获取订单详情成功!', $list);
    }

    /**
     * 支付订单成功
     * $id     int      默认为0
     * $title  string   默认为空
     * @desc 获取支付订单成功的信息
     */
    public function payOrders(Request $request)
    {
        $data = self::getData($this->class_name, 'payOrders');
        if ($data) {
            return $data;
        }
        $validator = Validator::make(
            $request->all(),
            OrderModel::rules(),
            OrderModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return errorJson($msg[0], []);
        }
        $list = OrderServices::getList($data);
        return successJson('获取支付订单成功!', $list);
    }

    /**
     * 创建订单
     */
    public function createOrder()
    {
        $list = self::getData('Orders','createOrder');

        return successJson('创建成功!', $list);
    }

    /**
     * 支付成功接口
     */
    public function payOrder()
    {
        $list = self::getData('Orders','payOrder');

        return successJson('支付成功!', $list);
    }

}
